package sort;

import common.Print;

/**
 * 插入排序
 */
public class InsertionSort {

    public static void main(String[] args) {
        int[] arr = {3,5,2,4,15,19,25,47,26,27,2,46,4,19,48,50};
        sort(arr);
        Print.printArr(arr);
    }

    public static void sort(int[] arr){
        for (int i = 0; i < arr.length; i++) {
            int temp = i;
            for (int j = temp; j >= 0; j--) {
                if(arr[j] > arr[temp]){
                    int tempValue = arr[temp];
                    while (j != temp){
                        arr[temp]=arr[temp-1];
                        temp--;
                    }
                    arr[j] = tempValue;
                }
            }
        }
    }
}
